package com.xy.bioapi.service;

import com.xy.bioapi.entity.Test;
import com.xy.bioapi.entity.TestResult;
import com.xy.bioapi.enums.ResultEnum;
import com.xy.bioapi.exception.TestException;
import com.xy.bioapi.repository.TestRepository;
import com.xy.bioapi.repository.TestResultRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * 实验结果数据
 * Created by DELL on 2017/7/11.
 */
@Service
public class TestResultService {

    @Autowired
    private TestResultRepository testResultRepository;

    /**
     * 保存实验结果数据
     * @param testResult
     */
    public void saveTestResult(TestResult testResult){
        try {
            testResultRepository.save(testResult);
        }catch (Exception e){
            e.printStackTrace();
        }

        /*if(testResultRepository.findByEquipmentId(testResult.getEquipmentId()) == null){
            testResultRepository.save(testResult);
            System.out.println("OK");
        }else{
            throw new TestException(ResultEnum.EQUIPMENT_EXISTED);
        }*/
    }

    /**
     * 通过设备ID获取实验结果数据集合
     * @param equipmentId
     * @return
     */
    public Set<TestResult> getTestResultByEquipmentId(Long equipmentId){

        if (equipmentId == null) {
            return null;
//            throw new TestException(ResultEnum.ILLEGAL_EQUIPMENT_ID);
        }else{
            return testResultRepository.findByEquipmentId(equipmentId);
        }
    }
}
